//
//  CelebrityHeaderCell.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/7/25.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "CelebrityHeaderCell.h"
#import "BigIntellgientModel.h"
#import "OpusListModel.h"
@implementation CelebrityHeaderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(void)setModel:(BigIntellgientModel *)model{
    _model = model;
    UIImageView *bgImageview = [[UIImageView alloc] init];
    NSString *picturlUrl = [NSString stringWithFormat:@"%@%@",PictureIp,_model.authorImagepath];
    NSLog(@"%@",picturlUrl);
    [bgImageview sd_setImageWithURL:[NSURL URLWithString:picturlUrl] placeholderImage:[UIImage imageNamed:@""]];
    [self addSubview:bgImageview];
    [bgImageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.height.mas_equalTo(cellScaleTopAndBottom(353));
    }];
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.text = _model.authorName;
    nameLabel.textColor = [UIColor whiteColor];
    [self addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(cellScaleLeftAndRight(20));
        make.top.equalTo(bgImageview.mas_bottom).offset(cellScaleTopAndBottom(20));
        make.height.mas_equalTo(cellScaleTopAndBottom(30));
        make.width.mas_equalTo(cellScaleLeftAndRight(100));
    }];
    UILabel *introduceLabel = [[UILabel alloc] init];
    introduceLabel.textColor = [UIColor whiteColor];
    introduceLabel.text = _model.auhtorIntroe;
    [self addSubview:introduceLabel];
    [introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLabel.mas_right).offset(cellScaleLeftAndRight(0));
        make.top.equalTo(bgImageview.mas_bottom).offset(cellScaleTopAndBottom(30));
        make.height.mas_equalTo(cellScaleTopAndBottom(20));
        make.right.equalTo(self.mas_right);
    }];
    UIView *lineview = [[UIView alloc] init];
    lineview.backgroundColor = [UIColor whiteColor];
    [self addSubview:lineview];
    [lineview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(cellScaleLeftAndRight(20));
        make.top.equalTo(nameLabel.mas_bottom).offset(cellScaleTopAndBottom(0));
        make.height.mas_equalTo(cellScaleTopAndBottom(1));
        make.right.equalTo(self.mas_right).offset(cellScaleLeftAndRight(-20));

    }];
    UILabel *detailLabel = [[UILabel alloc] init];
    detailLabel.numberOfLines = 0;
    detailLabel.textColor = [UIColor whiteColor];
//    detailLabel.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:216.0/255.0 blue:73.0/255.0 alpha:1];
    detailLabel.text = _model.auhtorDescrp;
    CGFloat height = [self getHeightLineWithString: _model.auhtorDescrp withWidth:cellScaleLeftAndRight(335) withFont:[UIFont systemFontOfSize:17]];
    [self addSubview:detailLabel];
    [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(cellScaleLeftAndRight(20));
        make.top.equalTo(lineview.mas_bottom).offset(cellScaleTopAndBottom(0));
        make.height.mas_equalTo(height);
        make.right.equalTo(self.mas_right).offset(cellScaleLeftAndRight(-20));
    }];
    
}
-(void)setHeaderModel:(OpusListModel *)headerModel{
    _headerModel = headerModel;
    UIImageView *bgImageview = [[UIImageView alloc] init];
    NSString *picturlUrl = [NSString stringWithFormat:@"%@%@",PictureIp,_headerModel.imagepath];
    NSLog(@"%@",picturlUrl);
    [bgImageview sd_setImageWithURL:[NSURL URLWithString:picturlUrl] placeholderImage:[UIImage imageNamed:@""]];
    [self addSubview:bgImageview];
    [bgImageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.height.mas_equalTo(cellScaleTopAndBottom(353));
    }];
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.text = _headerModel.name;
    nameLabel.textColor = [UIColor whiteColor];
    [self addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(cellScaleLeftAndRight(20));
        make.top.equalTo(bgImageview.mas_bottom).offset(cellScaleTopAndBottom(20));
        make.height.mas_equalTo(cellScaleTopAndBottom(30));
        make.width.mas_equalTo(cellScaleLeftAndRight(100));
    }];
    UILabel *introduceLabel = [[UILabel alloc] init];
    introduceLabel.textColor = [UIColor whiteColor];
    introduceLabel.text = _headerModel.authorTitle;
    [self addSubview:introduceLabel];
    [introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLabel.mas_right).offset(cellScaleLeftAndRight(0));
        make.top.equalTo(bgImageview.mas_bottom).offset(cellScaleTopAndBottom(30));
        make.height.mas_equalTo(cellScaleTopAndBottom(20));
        make.right.equalTo(self.mas_right);
    }];
    UIView *lineview = [[UIView alloc] init];
    lineview.backgroundColor = [UIColor whiteColor];
    [self addSubview:lineview];
    [lineview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(cellScaleLeftAndRight(20));
        make.top.equalTo(nameLabel.mas_bottom).offset(cellScaleTopAndBottom(0));
        make.height.mas_equalTo(cellScaleTopAndBottom(1));
        make.right.equalTo(self.mas_right).offset(cellScaleLeftAndRight(-20));
        
    }];
    UILabel *detailLabel = [[UILabel alloc] init];
    detailLabel.numberOfLines = 0;
    detailLabel.textColor = [UIColor whiteColor];
    //    detailLabel.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:216.0/255.0 blue:73.0/255.0 alpha:1];
    detailLabel.text = _headerModel.description;
    CGFloat height = [self getHeightLineWithString: _model.auhtorDescrp withWidth:cellScaleLeftAndRight(335) withFont:[UIFont systemFontOfSize:17]];
    [self addSubview:detailLabel];
    [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(cellScaleLeftAndRight(20));
        make.top.equalTo(lineview.mas_bottom).offset(cellScaleTopAndBottom(0));
        make.height.mas_equalTo(height);
        make.right.equalTo(self.mas_right).offset(cellScaleLeftAndRight(-20));
    }];

}
#pragma mark - 根据字符串计算label高度
- (CGFloat)getHeightLineWithString:(NSString *)string withWidth:(CGFloat)width withFont:(UIFont *)font {
    
    //1.1最大允许绘制的文本范围
    CGSize size = CGSizeMake(width, 2000);
    //1.2配置计算时的行截取方法,和contentLabel对应
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineSpacing:10];
    //1.3配置计算时的字体的大小
    //1.4配置属性字典
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:style};
    //2.计算
    //如果想保留多个枚举值,则枚举值中间加按位或|即可,并不是所有的枚举类型都可以按位或,只有枚举值的赋值中有左移运算符时才可以
    CGFloat height = [string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:dic context:nil].size.height;
    return height;
}

@end
